﻿// ==PREPROCESSOR==
// @name "DarkOne4Mod - Control Panel - Left"
// @version "1.1 build20161024"
// @author "tedGo, based on a sample created by T.P. Wang, using partial code by super-gau"
// @import "%fb2k_profile_path%cui-configs\darkone4mod\jscript\js\Global Config Script.js"
// @import "%fb2k_profile_path%cui-configs\darkone4mod\jscript\js\Global Button Script.js"
// @import "%fb2k_profile_path%cui-configs\darkone4mod\jscript\js\TextButton Object.js"
// @import "%fb2k_profile_path%cui-configs\darkone4mod\jscript\js\getButtonProperties.js"
// @import "%fb2k_profile_path%cui-configs\darkone4mod\jscript\js\getMainMenu.js"
// ==/PREPROCESSOR==

var p_backcol = RGBA(31, 31, 31, 255);
var bxf, bby, bbw, bbh, rbx = 0;

// ----- CREATE BUTTONS -----
btnOptions.font_name = "Arial Black";
btnOptions.text_h_align = 1;
btnOptions.btn_style = 1;
btnOptions.line_width = 1;

btnColours.text_normal = ui_btntxtcol;
btnColours.line_normal = RGBA(0, 0, 0, 255);
btnColours.back_hover = RGBA(255, 255, 255, 16);
btnColours.back_down = RGBA(255, 255, 255, 8);

var a_name = ["", "", "CONSOLE", "", "", "TIME"];
var a_func = [function(){fb.Exit()}, getMainMenu, function(){fb.ShowConsole()}, function(){fb.RunMainMenuCommand("Show Status pane")}, function(){fb.RunMainMenuCommand("Show Status bar")}, function(){window.SetProperty("01. Remain Time", t_r ? false : true); TimeOpt()}];
for (var i_ = 0; i_ >= 0 && i_ <= 5; i_++) Buttons["a_" + i_] = new TextButton(a_name[i_], a_func[i_], btnOptions, btnColours);

var b_name = ["BUTTON 01", "BUTTON 02", "BUTTON 03", "BUTTON 04", "BUTTON 05", "BUTTON 06", "BUTTON 07", "BUTTON 08"];
var b_btns = [];
for (var j_ in b_name) b_btns.push(getButtonProperties(b_name[j_], b_name[j_] + " name (up to 10 letters)", b_name[j_], b_name[j_] + " context menu command?", b_name[j_] + " command string"));
for (var k_ in b_btns) if (b_btns[k_].Exists) Buttons["b_" + k_] = new TextButton(b_btns[k_].Text, AddBtnCmd, btnOptions, btnColours, "", b_btns[k_]);

// ----- CREATE TIMESWITCH OPTION -----
function TimeOpt() {
	t_r = window.GetProperty("01. Remain Time", false);
	window.NotifyOthers("remTime", t_r);
}

TimeOpt();

// ----- DRAW -----
function on_paint(gr) {
	!window.IsTransparent && gr.FillSolidRect(0, 0, ww, wh, p_backcol);

	gr.SetInterpolationMode(7);
	gr.SetSmoothingMode(4);

	g_signs && gr.DrawImage(g_signs, 0, 0, bbw, bbh, 1206, 396, 150, 72);
	g_signs && gr.DrawImage(g_signs, ww - ww / 8 - 1, 0, bbw, bbh, 1674, 396, 150, 72);

	gr.GdiDrawText("PANE --- STATUS --- BAR", gdi.Font(btnOptions.font_name, btnSizeOpt.font_size), btnColours.text_normal, bxf * 3, bby, bbw * 2, Math.ceil(bbh / 3 * 2), 1);
	buttonsDraw(gr);
}

// ----- MOUSE ACTIONS -----
function on_mouse_move(x, y) {
	buttonsMouseMove(x, y);
}

function on_mouse_lbtn_down(x, y) {
	buttonsMouseLbtnDown(x, y);
}

function on_mouse_lbtn_up(x, y) {
	buttonsMouseLbtnUp(x, y);
}

function on_mouse_rbtn_up(x, y) {
	var a = window.CreatePopupMenu();
	var idx;

	a.AppendMenuItem(0, 1, "Manage optional buttons");
	a.AppendMenuItem(0, 2, "Configure...");

	idx = a.TrackPopupMenu(x, y);
	idx == 1 && window.ShowProperties();
	idx == 2 && window.ShowConfigure();

	a.Dispose();
	return true;
}

function on_mouse_leave() {
	buttonsMouseLeave();
}

// ----- EVENTS -----
function on_size() {
	ww = window.Width;
	wh = window.Height;
	bxf = ww / 16;
	bby = Math.floor(ww / 80 * 7) - 1;
	bbw = Math.floor(ww / 8);
	bbh = Math.floor(bbw / 25 * 12);
	rbx = ww - ww / 8 - 1;

	btnSizeOpt.font_size = ww * 7 / 400;
	btnSizeOpt.func_top_pad = Math.ceil(bbh / 3 * 2);

	Buttons.a_0.initPos(0, 0, bbw, bbh);
	Buttons.a_1.initPos(rbx, 0, bbw, bbh);

	var qx = [0, bxf * 3, bxf * 5, rbx];
	for (var i = 2; i >= 2 && i <= 5; i++) Buttons["a_" + i].initPos(qx[i - 2], bby, bbw, bbh, btnSizeOpt);
	for (var j = 0; j >= 0 && j <= 4; j++) b_btns[j].Exists && Buttons["b_" + j].initPos(bxf * (j * 2 + 3), 0, bbw, bbh, btnSizeOpt);
	for (var k = 5; k >= 5 && k <= 7; k++) b_btns[k].Exists && Buttons["b_" + k].initPos(bxf * (k * 2 - 3), bby, bbw, bbh, btnSizeOpt);
}